package firstchi.handler;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.style.UpdateAppearance;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button button = null;
    private Button button2 = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new button1Listener());
        button2 = (Button) findViewById(R.id.button2);
        button2.setOnClickListener(new button2Listener());
    }
        final Handler handler = new Handler();
        class button1Listener implements View.OnClickListener {
            @Override
            public void onClick(View v) {
                handler.post(updateThread);
            }
        }

        class button2Listener implements View.OnClickListener {
            @Override
            public void onClick(View v) {
                handler.removeCallbacks(updateThread);
            }

        }

        Runnable updateThread = new Runnable() {
            @Override
            public void run() {
                System.out.println("updateThread");
                Log.v("tag", "updateThread");
                handler.postDelayed(updateThread, 2000);


            }
        };






    }

